function submit_action_admin(id, uri, action)
{
    $('input[name=id]').val(id);

    if (action=='delete')
        if ( !confirm('Bạn có thực sự muốn xóa không?'))
            return;

    $('#submit_form').attr('action', uri);
    $('#submit_form').submit();
}

function change_status(id, modules)
{
    $.ajax(
    {
        type:'post',
        url : '/dashboard/' + modules + '/change_status',
        data:{
            'id' : id
        },
        success: function()
        {
            return true;
        }
    });
}

function change_home(id, modules)
{
    $.ajax(
    {
        type:'post',
        url : '/dashboard/'+ modules +'/change_home',
        data:{
            'id' : id
        },
        success: function()
        {
            return true;
        }
    });
}
function change_home_cat(id, modules)
{
    $.ajax(
    {
        type:'post',
        url : '/dashboard/'+ modules +'/cat/change_home',
        data:{
            'id' : id
        },
        success: function()
        {
            return true;
        }
    });
}

function change_grid_cat(id, modules)
{
    $.ajax(
    {
        type:'post',
        url : '/dashboard/'+ modules +'/cat/change_grid',
        data:{
            'id' : id
        },
        success: function()
        {
            return true;
        }
    });
}

function change_private(id, modules)
{
    $.ajax(
    {
        type:'post',
        url : '/dashboard/'+ modules +'/change_private',
        data:{
            'id' : id
        },
        success: function()
        {
            return true;
        }
    });
}
function change_private_cat(id, modules)
{
    $.ajax(
    {
        type:'post',
        url : '/dashboard/'+ modules +'/cat/change_private',
        data:{
            'id' : id
        },
        success: function()
        {
            return true;
        }
    });
}

function change_menus()
{
    var cat_id = $("select[name=menus_categories]").val();
    $.ajax(
    {
        type:'post',
        url : '/dashboard/menus/change_menus',
        data:{
            'cat_id' : cat_id
        },
        dataType: "html",
        beforeSend: function(){
            $('#navigation_menus').html("Đang tải...");  
        },
        success: function(data)
        {
            $('#navigation_menus').html(data);  
        }
    });
}

function startups_check()
{
    ss = $('input[name=startups]').val();
    if(ss == '' || ss == 0){
        $('input[name=startups]').val(1);
    }else{
        $('input[name=startups]').val(0);
    }
}

function change_startups(id, modules)
{
    $.ajax(
    {
        type:'post',
        url : '/dashboard/'+ modules +'/change_startups',
        data:{
            'id'        : id
        },
        success: function()
        {
            return true;
        }
    });
}

function uploadify(){
    if($('#session_upload').val() === null) return;
    var session_upload      = $('#session_upload').val() ;
    var process_url     = $('#process_url').val();
    $('#file_upload').uploadify({
        'swf'               : '/powercms/scripts/uploadify/uploadify.swf',
        'formData'          : {'session_upload' : session_upload},
        'uploader'          : process_url,
        'fileTypeExt'       : '*.jpg; *.jpeg; *.gif; *.png',
        'fileTypeDesc'      : 'Image Files (.JPG, .JPEG, .GIF, .PNG)',
        'fileSizeLimit'     : '1MB',
        'removeTimeout'     : 1,
        'buttonText'        : 'Chọn ảnh',
        'onUploadSuccess'   : function(file, data, response) {
            //alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
        },
        'onQueueComplete': function ()
        {
            if(process_url === '/upload_products_images')
            {
                $.ajax(
                {
                    type:   'post',
                    url:    '/get_products_images',
                    data:   {
                        'is-ajax'           : 1
                    },
                    success: function(responseText)
                    {
                        var object = document.getElementById("products_images").childNodes[1];
                        object.innerHTML = responseText;
                        set_hover_img();
                    }
                });
            }
            else if(process_url === '/upload_gallery_images')
            {
                $.ajax(
                {
                    type:   'post',
                    url:    '/get_gallery_images',
                    data:   {
                        'is-ajax'           : 1
                    },
                    success: function(responseText)
                    {
                        var object = document.getElementById("gallery_images").childNodes[1];
                        object.innerHTML = responseText;
                        set_hover_img();
                    }
                });
            }
            else if(process_url == '/upload_album_images')
            {
                $.ajax(
                {
                    type:   'post',
                    url:    '/get_album_images',
                    data:   {
                        'is-ajax'           : 1
                    },
                    success: function(responseText)
                    {
                        var object = document.getElementById("albums_images").childNodes[1];
                        object.innerHTML = responseText;
                        editable();
                    }
                });
            }
        }
      });
}

function setup_moveable() {

    // thay đổi vị trí ảnh của sản phẩm
    $("#products_images ul").sortable({
        opacity: 0.6,
        cursor: 'move',
        update: function() {
            var order = $(this).sortable("serialize");
            $.post('/sort_products_images', order, function(data){
                $('#sort_success').fadeIn(1600);
                $('#sort_success').fadeOut(1600, 'linear');
            });
        }
    });
    
    // thay doi vi tri anh gallery
    $("#gallery_images ul").sortable({
        opacity: 0.6,
        cursor: 'move',
        update: function() {
            var order = $(this).sortable("serialize");
            $.post('/sort_gallery_images', order, function(data){
                $('#sort_success').fadeIn(1600);
                $('#sort_success').fadeOut(1600, 'linear');
            });
        }
    });
    
    // thay doi vi tri 
    $("#videos_items ul").sortable({
        opacity: 0.6,
        cursor: 'move',
        update: function() {
            var order = $(this).sortable("serialize");
            $.post('/sort_videos_items', order, function(data){
                $('#sort_success').fadeIn(1600);
                $('#sort_success').fadeOut(1600, 'linear');
            });
        }
    });

    //thay đổi vị trí hỗ trợ trực tuyến
    $("#sort_support ul").sortable({
        opacity: 0.6,
        cursor: 'move',
        update: function() {
            var order = $(this).sortable("serialize");
            $.post('/supports/sort', order, function(data){
                });
        }
    });

    //thay đổi vị trí quảng cáo
    $("#sort_advertisement ul").sortable({
        opacity: 0.6,
        cursor: 'move',
        update: function() {
            var order = $(this).sortable("serialize");
            $.post('/advs/sort', order, function(data){
                });
        }
    });

    // sắp xếp các ảnh trong album
    $("#albums_images ul").sortable({
        opacity: 0.6,
        cursor: 'move',
        update: function() {
            var order = $(this).sortable("serialize");
            $.post('/albums/sort_album_image', order, function(data){
                });
        }
    });

    // sắp xếp album
    $("#sort_album ul").sortable({
        opacity: 0.6,
        cursor: 'move',
        update: function() {
            var order = $(this).sortable("serialize");
            $.post('/albums/sort_album', order, function(data){
                });
        }
    });

    // sắp xếp vị trí của menu
    $("#sort_menu ul").sortable({
        opacity: 0.6,
        cursor: 'move',
        update: function() {
            var order = $(this).sortable("serialize");
            $.post('/menus/sort', order, function(data){
                });
        }
    });
    
    // sắp xếp vị trí của danh mục sản phẩm
    $("#sort_cat ul").sortable({
        opacity: 0.6,
        cursor: 'move',
        update: function() {
            var order = $(this).sortable("serialize");
            $.post('/products_categories/sort', order, function(data){
                });
        }
    });
    
    //Sắp sếp đơn vị
    $("#sort_units ul").sortable({
        opacity: 0.6,
        cursor: 'move',
        update: function() {
            var order = $(this).sortable("serialize");
            $.post('/units/sort', order, function(data){
                });
        }
    });
}

function enable_advanced_wysiwyg(selector)
{
    tinyMCE.init({
        mode : "textareas",
        editor_selector : selector,
        theme : "advanced",
        invalid_elements : "div,script,abbr,acronym,address,applet,area,bdo,big,blockquote,button,caption,cite,code,col,colgroup,dd,del,dfn,input,ins,isindex,kbd,label,legend,map,menu,noscript,optgroup,option,param,textarea,var,ruby,samp,select,rtc,hr",
        extended_valid_elements : "iframe[src|width|height|name|align]",
        height: "300px",
        plugins : "paste,inlinepopups,imagemanager,contextmenu,table,heading,preview, media",
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,|,formatselect,fontselect,fontsizeselect,|,image,table, media, code",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_path_location : "bottom",
        paste_remove_styles: true,
//        paste_remove_spans: false,
        paste_remove_styles_if_webkit: true,
        entity_encoding : "raw",
        language : 'en',
        theme_advanced_buttons1_add : "forecolor,backcolor,separator,link,unlink,pasteword,removeformat,preview, media",
        plugin_preview_width : "640",
        plugin_preview_height : "480",
        convert_urls : false,
        setup : function(ed) {
            ed.onInit.add(function() {
                ed.settings.file_browser_callback = function(field_name, url, type, win) {
                    if (type == 'image')
                        mcImageManager.filebrowserCallBack(field_name, url, type, win);
                    else
                        alert('Do other stuff here');
                };
            });
        }
    });
}

function enable_tiny_mce()
{
    tinymce.init({
        selector: "textarea.elm1",
        theme: "modern",
        width: 800,
        height: 300,
//        language: 'vi',
        plugins: [
             "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
             "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
             "save table contextmenu directionality emoticons template paste textcolor"
       ],
       content_css: "css/content.css",
       toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | l      ink image | print preview media fullpage | forecolor backcolor | formatselect fontselect fontsizeselect | link unlink | removeformat",
       
       style_formats: [
            {title: 'Bold text', inline: 'b'},
            {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
            {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
            {title: 'Example 1', inline: 'span', classes: 'example1'},
            {title: 'Example 2', inline: 'span', classes: 'example2'},
            {title: 'Table styles'},
            {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
        ],
        relative_urls: false,
        remove_script_host: false,
        invalid_elements : "div,script,abbr,acronym,address,applet,area,bdo,big,blockquote,button,caption,cite,code,col,colgroup,dd,del,dfn,input,ins,isindex,kbd,label,legend,map,menu,noscript,optgroup,option,param,textarea,var,ruby,samp,select,rtc,hr",
        extended_valid_elements : "iframe[src|width|height|name|align]",
//        paste_as_text: true,
//        paste_word_valid_elements: "b,strong,i,em,h1,h2",
//        paste_webkit_styles: "color font-size",
//        paste_retain_style_properties: "color font-size",
//        paste_merge_formats: false,
//        paste_convert_word_fake_lists: false,
        external_filemanager_path:"/plugins/tinymce/plugins/filemanager/",
        filemanager_title:"Quản lý tập tin" ,
        external_plugins: { "filemanager" : "plugins/filemanager/plugin.min.js"}
     });
}

function change_feedback_status(id)
{
    $.ajax(
    {
        type:'post',
        url : '/change_feedback_status',
        data:{
            'id'        : id
        },
        success: function()
        {
            return true;
        }
    });
}

function submit_feedback(id, action)
{
    $('input[name=feedback_id]').val(id);
    if (action=='delete')
        if ( !confirm('Bạn có thực sự muốn xóa ý kiến này không?'))
            return;

    $('#feedback_form').attr('action', '/dashboard/feedbacks/' + action);
    $('#feedback_form').submit();
}

function tabs()
{
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function() {
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });
}

function setup_datepicker() {
    $("#starting_date").datepicker({
                    dateFormat: 'dd/mm/yy',
                    minDate:0
                    
            }
    );
    $("#ending_date").datepicker({
                dateFormat: 'dd/mm/yy',
                minDate:0
        }
    );
//    $("#news_created_date").datepicker({
//        dateFormat: 'dd-mm-yy'
//    });
    $("#news_created_date").datetimepicker({
        timeFormat: 'HH:mm',
//        showTimepicker: true,
        dateFormat: 'dd-mm-yy',
    });
    $("#start_day_date").datepicker({
        dateFormat: 'dd-mm-yy'
    });
    $("#end_day_date").datepicker({
        dateFormat: 'dd-mm-yy'
    }
    );
    $('#from_date').datepicker({dateFormat: 'dd/mm/yy'});
    $('#to_date').datepicker({dateFormat: 'dd/mm/yy'});
}

function show_add_product_form()
{
    $("#add_product").toggle("slow");
}

function show_add_product_form_excel()
{
    $("#add_product_excel").toggle("slow");
}

function show_add_gallery_form()
{
    $("#add_gallery").toggle("slow");
}

//videos

function getYoutubeID(url) {
    var id = url.match("[\\?&]v=([^&#]*)");
    id = id[1];
    return id;
};

function show_add_videos_form()
{
    $("#add_videos").toggle("slow");
}

function add_video()
{
    var video_item_url = $('#video_item_url').val();
    var youtube_id = getYoutubeID(video_item_url);
    
    if(video_item_url === ''){
        $("#video_item_url").animate({
            borderColor: "1px solid #f56954"
        }, 'fast' );
        $("#video_item_url").delay(500).animate({
            borderColor: "1px solid #ccc"
        }, 'slow');
        return;
    }else{
        var video_id = $('input[name=id]').val();
        $.ajax(
        {
            type:   'post',
            url:    '/add_videos_items',
            data:   {
                'is-ajax' : 1,
                'video_id' : video_id,
                'url' : video_item_url,
                'youtube_id' : youtube_id
            },
            success: function(responseText)
            {
                var object = document.getElementById("videos_items").childNodes[1];
                object.innerHTML = responseText;
                set_hover_img();
            }
        });
    }
}

function add_caption_videos_items(id)
{
    var caption = $('#caption_' + id).val();

    $.ajax(
    {
        type: 'post',
        url: '/add_caption_videos_items',
        data: {
            'id': id,
            'caption': caption,
        },
        success: function()
        {
            $('#add_caption_success').fadeIn(1600);
            $('#add_caption_success').fadeOut(1600, 'linear');
        }
    });
}

function delete_videos_items(id)
{
    $.ajax(
    {
        type:   'post',
        url:    '/delete_videos_items',
        data:   {
            'is-ajax'           : 1,
            'id'                : id
        },
        success: function(responseText)
        {
            var object = document.getElementById("videos_items").childNodes[1];
            object.innerHTML = responseText;
            set_hover_img();
        }
    });
}

function delete_products_images(id)
{
    $.ajax(
    {
        type:   'post',
        url:    '/delete_products_images',
        data:   {
            'is-ajax'           : 1,
            'id'                : id
        },
        success: function(responseText)
        {
            var object = document.getElementById("products_images").childNodes[1];
            object.innerHTML = responseText;
            set_hover_img();
        }
    });
}

function delete_gallery_images(id)
{
    $.ajax(
    {
        type:   'post',
        url:    '/delete_gallery_images',
        data:   {
            'is-ajax'           : 1,
            'id'                : id
        },
        success: function(responseText)
        {
            var object = document.getElementById("gallery_images").childNodes[1];
            object.innerHTML = responseText;
            set_hover_img();
        }
    });
}

//anh thumb
function GetFilenameFromPath()
{
    var filePath = $('#url_abs').val();
    var first_url = filePath.substring(0,filePath.lastIndexOf("/")+1);
    var last_url = filePath.substring(filePath.lastIndexOf("/")+1);
    $('#url_abs').val(first_url + 'thumb/' + last_url);
}

//anh goc
function GetFilenameFromPath2()
{
    var filePath = $('#url_abs').val();
    var first_url = filePath.substring(0,filePath.lastIndexOf("/")+1);
    var last_url = filePath.substring(filePath.lastIndexOf("/")+1);
    $('#url_abs').val(first_url + last_url);
}

function change_page_admin(offset, per_page)
{
    var current_uri = $('input[name=uri]').val();
    var page = offset / per_page + 1;
    var url = current_uri + '/page-' + page;

    location.href = url;
    return;
}

function show_child(id)
{
    $("#list_item_" + id).toggle("slow");
}

function toggle_form(id)
{
    $("#" + id).toggle("slow");
}

function set_hover_img()
{
    var setHover = $(".t-wrapper .t-square");
    setHover.each(function(){
        var del = $(this).find(".delete_me")
        $(this).hover(function(){
        del.css("display", "block");
        }, function(){
            del.css("display", "none");
        })
    })
}

function change_time()
{
    var chart_time_combobox  = $("select[name=chart_time_combobox]").val();
    var back_url    = $("input[name=back_url]").val();
    $.ajax(
    {
        type:'post',
        url : back_url,
        data:{
            'chart_time_combobox' : chart_time_combobox
        },
        beforeSend: function(){
            $('#loadingtext').html('Đang tải');
        },
        success: function()
        {
            return true;
        }
    });
}

function change_sort()
{
    var sort_combobox = $("select[name=sort_combobox]").val();
    var submit_url    = $("input[name=submit_url]").val();
    var redirect_url    = $("input[name=redirect_url]").val();
    var lang        = $("select[name=lang]").val();
    $.ajax({
        type:'post',
        url : submit_url,
        data:{
            'sort_combobox' : sort_combobox
        },
        success: function()
        {
            location.href = redirect_url + '/' + lang;
        }
    });
}

function change_lang()
{
    var lang        = $("select[name=lang]").val();
    var back_url    = $("input[name=back_url]").val();
    location.href = back_url + '/' + lang;
}

//categories
function get_categories_by_lang()
{
    var lang = $('select[name=lang]').val();
    var cat_id = $('input[name=cat_id]').val();
    //  nếu là thêm và sửa category
    var flag = typeof($('input[name=is_add_edit_category]').val()) != 'undefined' ? $('input[name=is_add_edit_category]').val() : 0;
    
    var form = $('input[name=form]').val()
    
    if(form == 'news_cat')
        my_url = '/get_news_categories_by_lang';
    else if(form == 'products_cat')
        my_url = '/get_products_categories_by_lang';
    else if(form == 'gallery_cat')
        my_url = '/get_gallery_categories_by_lang';
    else if(form == 'videos_cat')
        my_url = '/get_videos_categories_by_lang';
    else if(form == 'download_cat')
        my_url = '/get_download_categories_by_lang';
    else if(form == 'faq_cat')
        my_url = '/get_faq_categories_by_lang';
    
    $.ajax(
    {
        type:   'post',
        url:    my_url,
        data:   {
            'is-ajax'      : 1,
            'lang'         : lang,
            'is_add_edit'  : flag,
            'cat_id'       : cat_id,
        },
        success: function(responseText) {
            if ($('#category'))
                $('#category').html(responseText);
        }
    });
}

function set_datetimepicker()
{
    var startDateTextBox = $('#start_date_time');
    var endDateTextBox = $('#end_date_time');

    startDateTextBox.datetimepicker({ 
            timeFormat: 'HH:mm',
            onClose: function(dateText, inst) {
                    if (endDateTextBox.val() != '') {
                            var testStartDate = startDateTextBox.datetimepicker('getDate');
                            var testEndDate = endDateTextBox.datetimepicker('getDate');
                            if (testStartDate > testEndDate)
                                    endDateTextBox.datetimepicker('setDate', testStartDate);
                    }
                    else {
                            endDateTextBox.val(dateText);
                    }
            },
            onSelect: function (selectedDateTime){
                    endDateTextBox.datetimepicker('option', 'minDate', startDateTextBox.datetimepicker('getDate') );
            }
    });
    endDateTextBox.datetimepicker({ 
            timeFormat: 'HH:mm',
            onClose: function(dateText, inst) {
                    if (startDateTextBox.val() != '') {
                            var testStartDate = startDateTextBox.datetimepicker('getDate');
                            var testEndDate = endDateTextBox.datetimepicker('getDate');
                            if (testStartDate > testEndDate)
                                    startDateTextBox.datetimepicker('setDate', testEndDate);
                    }
                    else {
                            startDateTextBox.val(dateText);
                    }
            },
            onSelect: function (selectedDateTime){
                    startDateTextBox.datetimepicker('option', 'maxDate', endDateTextBox.datetimepicker('getDate') );
            }
    });
}

function timelimited_check()
{
    ss = $('input[name=timelimited]').val();
    if(ss == '' || ss == 0){
        $('input[name=timelimited]').val(1);
        $('#timelimited-area').show('blind', 200);
    }else{
        $('input[name=timelimited]').val(0);
        $('#start_date_time').val('');
        $('#end_date_time').val('');
        $('#timelimited-area').hide('blind',200);
    }
}

function uploadify_download(){
    if($('#session_upload_file').val() === null) return;
    var session_upload      = $('#session_upload_file').val() ;
    var process_url     = $('#process_url_file').val();
    $('#download_file_upload').uploadify({
        'swf'               : '/powercms/scripts/uploadify/uploadify.swf',
        'formData'          : {'session_upload' : session_upload},
        'uploader'          : process_url,
        'fileTypeExt'       : '*.*',
        'fileTypeDesc'      : 'All Files (*.*)',
        'fileSizeLimit'     : '50MB',
        'removeTimeout'     : 1,
        'buttonText'        : 'Chọn và upload File',
        'onUploadSuccess'   : function(file, data, response) {
            //alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
        },
        'onQueueComplete': function ()
        {
            if(process_url === '/upload_file_download')
            {
                $.ajax(
                {
                    type:   'post',
                    url:    '/get_file_download',
                    data:   {
                        'is-ajax'           : 1
                    },
                    success: function(responseText)
                    {
                        var object = document.getElementById("download_file").childNodes[1];
                        object.innerHTML = responseText;
                        set_hover_img();
                    }
                });
            }
        }
      });
}

function delete_file_download(id)
{
    $.ajax(
    {
        type:   'post',
        url:    '/delete_file_download',
        data:   {
            'is-ajax' : 1,
            'id'      : id
        },
        success: function(responseText)
        {
            var object = document.getElementById("download_file").childNodes[1];
            object.innerHTML = responseText;
            set_hover_img();
        }
    });
}

function add_caption_image_gallery(id)
{
    var caption = $('#caption_' + id).val();

    $.ajax(
    {
        type: 'post',
        url: '/add_caption_image_gallery',
        data: {
            'id': id,
            'caption': caption,
        },
        success: function()
        {
            $('#add_caption_success').fadeIn(1600);
            $('#add_caption_success').fadeOut(1600, 'linear');
        }
    });
}

function roles_all_check()
{
    $('#roles_all').click(function(event) {
    if(this.checked) {
        $('input[name="roles[]"]').each(function() {
            this.checked = true;
            this.disabled = true;
        });
    } else {
      $('input[name="roles[]"]').each(function() {
            this.checked = false;
            this.disabled = false;
        });
    }
  });
  if($('#roles_all').attr('checked')){
      $('input[name="roles[]"]').each(function() {
        this.checked = true;
        this.disabled = true;
    });
  }
}

function string_to_slug(str) {
  str = str.replace(/^\s+|\s+$/g, ''); // trim
  str = str.toLowerCase();
  // remove accents, swap ñ for n, etc
  //var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
  //var to   = "aaaaeeeeiiiioooouuuunc------";
  var from = "àáạảãâầấậẩẫăằắặẳẵäèéẹẻẽêềếệểễëìíịỉĩòóọỏõôồốộổỗơờớợởỡöùúụủũưừứựửữüûỳýỵỷỹđñç·/_,:;";
  var to   = "aaaaaaaaaaaaaaaaaaeeeeeeeeeeeeiiiiioooooooooooooooooouuuuuuuuuuuuuyyyyydnc------";
  for (var i=0, l=from.length ; i<l ; i++) {
    str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
  }
  str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
    .replace(/\s+/g, '-') // collapse whitespace and replace by -
    .replace(/-+/g, '-'); // collapse dashes
  return str;
}

function convert_to_slug(val)
{
    var slug = string_to_slug(val);
    $('input[name=slug]').val(slug);
}

$(document).ready(function()
{
    uploadify_download();
    set_hover_img();
    setTimeout(function () {
        uploadify();
    },0);
    tabs();
    setup_datepicker();
    setup_moveable();
    set_datetimepicker();
    roles_all_check();
});